<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>论文写作 | 小熊的技术文档</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/fav.ico">
    <link rel="stylesheet" href="/css/katex.min.css">
    <link rel="stylesheet" href="/css/github-markdown.min.css">
    <meta name="description" content="衣带渐宽终不悔，为伊消得人憔悴">
    
    <link rel="preload" href="/assets/css/0.styles.e6449353.css" as="style"><link rel="preload" href="/assets/js/app.9e067b79.js" as="script"><link rel="preload" href="/assets/js/2.983eb755.js" as="script"><link rel="preload" href="/assets/js/59.5ab55a80.js" as="script"><link rel="prefetch" href="/assets/js/10.79548333.js"><link rel="prefetch" href="/assets/js/11.31600f80.js"><link rel="prefetch" href="/assets/js/12.62bd3528.js"><link rel="prefetch" href="/assets/js/13.de8b1ace.js"><link rel="prefetch" href="/assets/js/14.f5db1e75.js"><link rel="prefetch" href="/assets/js/15.bf827d4d.js"><link rel="prefetch" href="/assets/js/16.cc9a1a73.js"><link rel="prefetch" href="/assets/js/17.2cfaefeb.js"><link rel="prefetch" href="/assets/js/18.3af7782b.js"><link rel="prefetch" href="/assets/js/19.639f7e7b.js"><link rel="prefetch" href="/assets/js/20.dc862f59.js"><link rel="prefetch" href="/assets/js/21.916e1685.js"><link rel="prefetch" href="/assets/js/22.d7a955f4.js"><link rel="prefetch" href="/assets/js/23.078391ef.js"><link rel="prefetch" href="/assets/js/24.bb460a5a.js"><link rel="prefetch" href="/assets/js/25.d69f2326.js"><link rel="prefetch" href="/assets/js/26.6da7ea48.js"><link rel="prefetch" href="/assets/js/27.82e23d91.js"><link rel="prefetch" href="/assets/js/28.9073bbec.js"><link rel="prefetch" href="/assets/js/29.639259a4.js"><link rel="prefetch" href="/assets/js/3.e594e5b2.js"><link rel="prefetch" href="/assets/js/30.b49c622d.js"><link rel="prefetch" href="/assets/js/31.92f6c8b3.js"><link rel="prefetch" href="/assets/js/32.42419088.js"><link rel="prefetch" href="/assets/js/33.c82e2ab8.js"><link rel="prefetch" href="/assets/js/34.381de37e.js"><link rel="prefetch" href="/assets/js/35.5e86d478.js"><link rel="prefetch" href="/assets/js/36.31f218ce.js"><link rel="prefetch" href="/assets/js/37.0d287b3f.js"><link rel="prefetch" href="/assets/js/38.1324cf44.js"><link rel="prefetch" href="/assets/js/39.de6bdb51.js"><link rel="prefetch" href="/assets/js/4.440c4dd9.js"><link rel="prefetch" href="/assets/js/40.a22c9c27.js"><link rel="prefetch" href="/assets/js/41.4637d617.js"><link rel="prefetch" href="/assets/js/42.db815e2b.js"><link rel="prefetch" href="/assets/js/43.f0955a92.js"><link rel="prefetch" href="/assets/js/44.7d5faddf.js"><link rel="prefetch" href="/assets/js/45.a88ffc33.js"><link rel="prefetch" href="/assets/js/46.883caa71.js"><link rel="prefetch" href="/assets/js/47.6f2cfd60.js"><link rel="prefetch" href="/assets/js/48.ea25654e.js"><link rel="prefetch" href="/assets/js/49.f38c23a0.js"><link rel="prefetch" href="/assets/js/5.e8844f36.js"><link rel="prefetch" href="/assets/js/50.e03dd8e9.js"><link rel="prefetch" href="/assets/js/51.f6160d52.js"><link rel="prefetch" href="/assets/js/52.4daa8322.js"><link rel="prefetch" href="/assets/js/53.b30992e9.js"><link rel="prefetch" href="/assets/js/54.209f17e1.js"><link rel="prefetch" href="/assets/js/55.4f1dd95b.js"><link rel="prefetch" href="/assets/js/56.147ea3e8.js"><link rel="prefetch" href="/assets/js/57.5823e0e2.js"><link rel="prefetch" href="/assets/js/58.772320f9.js"><link rel="prefetch" href="/assets/js/6.54e1cc95.js"><link rel="prefetch" href="/assets/js/60.b47b75bb.js"><link rel="prefetch" href="/assets/js/61.0cd5a012.js"><link rel="prefetch" href="/assets/js/62.35eb5453.js"><link rel="prefetch" href="/assets/js/63.d31f2118.js"><link rel="prefetch" href="/assets/js/64.03d35d7c.js"><link rel="prefetch" href="/assets/js/65.8bdc633f.js"><link rel="prefetch" href="/assets/js/66.dbbe8867.js"><link rel="prefetch" href="/assets/js/67.228613b5.js"><link rel="prefetch" href="/assets/js/68.d10a2687.js"><link rel="prefetch" href="/assets/js/69.7903847f.js"><link rel="prefetch" href="/assets/js/7.f5ab00eb.js"><link rel="prefetch" href="/assets/js/70.11ee4e27.js"><link rel="prefetch" href="/assets/js/8.95b39934.js"><link rel="prefetch" href="/assets/js/9.26cfd48c.js">
    <link rel="stylesheet" href="/assets/css/0.styles.e6449353.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">小熊的技术文档</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/front-end/" class="nav-link">
  🎨前端
</a></div><div class="nav-item"><a href="/back-end/" class="nav-link">
  💻后端
</a></div><div class="nav-item"><a href="/practice/" class="nav-link">
  🚀实战
</a></div><div class="nav-item"><a href="/office/" class="nav-link">
  🏢办公
</a></div><div class="nav-item"><a href="/general/" class="nav-link">
  🍓通用
</a></div><div class="nav-item"><a href="/paper/" class="nav-link router-link-active">
  🐸论文
</a></div><div class="nav-item"><a href="/general/fast.html" class="nav-link">
  ⚡快速笔记
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="🦉近期重点" class="dropdown-title"><span class="title">🦉近期重点</span> <span class="arrow down"></span></button> <button type="button" aria-label="🦉近期重点" class="mobile-dropdown-title"><span class="title">🦉近期重点</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/back-end/python.html" class="nav-link">
  🐇python常用模块
</a></li><li class="dropdown-item"><!----> <a href="/practice/zrender.html" class="nav-link">
  🌹zrender源码解析
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="⭐️资源" class="dropdown-title"><span class="title">⭐️资源</span> <span class="arrow down"></span></button> <button type="button" aria-label="⭐️资源" class="mobile-dropdown-title"><span class="title">⭐️资源</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://www.birdiesearch.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  小鸟搜索
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://salttiger.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  每天一本编程书
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/docmirror/dev-sidecar" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开发者边车
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/front-end/" class="nav-link">
  🎨前端
</a></div><div class="nav-item"><a href="/back-end/" class="nav-link">
  💻后端
</a></div><div class="nav-item"><a href="/practice/" class="nav-link">
  🚀实战
</a></div><div class="nav-item"><a href="/office/" class="nav-link">
  🏢办公
</a></div><div class="nav-item"><a href="/general/" class="nav-link">
  🍓通用
</a></div><div class="nav-item"><a href="/paper/" class="nav-link router-link-active">
  🐸论文
</a></div><div class="nav-item"><a href="/general/fast.html" class="nav-link">
  ⚡快速笔记
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="🦉近期重点" class="dropdown-title"><span class="title">🦉近期重点</span> <span class="arrow down"></span></button> <button type="button" aria-label="🦉近期重点" class="mobile-dropdown-title"><span class="title">🦉近期重点</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/back-end/python.html" class="nav-link">
  🐇python常用模块
</a></li><li class="dropdown-item"><!----> <a href="/practice/zrender.html" class="nav-link">
  🌹zrender源码解析
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="⭐️资源" class="dropdown-title"><span class="title">⭐️资源</span> <span class="arrow down"></span></button> <button type="button" aria-label="⭐️资源" class="mobile-dropdown-title"><span class="title">⭐️资源</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://www.birdiesearch.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  小鸟搜索
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://salttiger.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  每天一本编程书
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/docmirror/dev-sidecar" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开发者边车
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/paper/writing.html" aria-current="page" class="active sidebar-link">论文写作</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/paper/writing.html#论文写作资源搜索" class="sidebar-link">论文写作资源搜索</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/paper/writing.html#论文下载" class="sidebar-link">论文下载</a></li><li class="sidebar-sub-header"><a href="/paper/writing.html#知网期刊批量下载" class="sidebar-link">知网期刊批量下载</a></li><li class="sidebar-sub-header"><a href="/paper/writing.html#得到知识搜索" class="sidebar-link">得到知识搜索</a></li></ul></li><li class="sidebar-sub-header"><a href="/paper/writing.html#全文翻译英文技术文档和书籍" class="sidebar-link">全文翻译英文技术文档和书籍</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/paper/writing.html#mobi、epub等格式的英文技术文档全文翻译" class="sidebar-link">mobi、epub等格式的英文技术文档全文翻译</a></li><li class="sidebar-sub-header"><a href="/paper/writing.html#pdf格式的英文文档全文翻译" class="sidebar-link">pdf格式的英文文档全文翻译</a></li><li class="sidebar-sub-header"><a href="/paper/writing.html#英文pdf使用有道文档翻译-网易翻译" class="sidebar-link">英文pdf使用有道文档翻译(网易翻译)</a></li><li class="sidebar-sub-header"><a href="/paper/writing.html#删除有道文档翻译下载的所有翻译图片并生成pdf合集" class="sidebar-link">删除有道文档翻译下载的所有翻译图片并生成pdf合集</a></li></ul></li></ul></li><li><a href="/paper/search.html" class="sidebar-link">无人机搜索</a></li><li><a href="/paper/defense.html" class="sidebar-link">防御无人机</a></li><li><a href="/paper/cover.html" class="sidebar-link">覆盖问题</a></li><li><a href="/paper/2020Auguest.html" class="sidebar-link">2020年8月归档</a></li><li><a href="/paper/daily.html" class="sidebar-link">每天一篇SCI论文</a></li><li><a href="/paper/technology.html" class="sidebar-link">国防科技框架</a></li><li><a href="/paper/strategy.html" class="sidebar-link">国防科技策略2030</a></li><li><a href="/paper/mpc.html" class="sidebar-link">模型预测控制</a></li><li><a href="/paper/MARL.html" class="sidebar-link">多智能体强化学习论文集</a></li><li><a href="/paper/UAV.html" class="sidebar-link">无人机</a></li><li><a href="/paper/clustering.html" class="sidebar-link">常用聚类算法</a></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="论文写作"><a href="#论文写作" class="header-anchor">#</a> 论文写作</h1> <h2 id="论文写作资源搜索"><a href="#论文写作资源搜索" class="header-anchor">#</a> 论文写作资源搜索</h2> <h3 id="论文下载"><a href="#论文下载" class="header-anchor">#</a> 论文下载</h3> <p>2021年8月可用的账号如下所示：</p> <table><thead><tr><th>学校</th> <th>账户</th> <th>password</th> <th>数据库地址</th></tr></thead> <tbody><tr><td>信工大</td> <td>休闲广场大学1~200</td> <td>xxgcdxtsg</td> <td>https://www.cnki.net/</td></tr> <tr><td>国大军文</td> <td>精神文化效益01~10</td> <td>jswhxy01~10</td> <td>https://www.cnki.net/</td></tr> <tr><td>陆工大</td> <td>路径过程对象001~120</td> <td>cnki001~120</td> <td>https://www.cnki.net/</td></tr> <tr><td>国大军文</td> <td>DX2029</td> <td>官方介绍武汉</td> <td>https://www.cnki.net/</td></tr> <tr><td>空工大</td> <td>科技广场对象01~10</td> <td>科技广场对象01~10</td> <td>https://www.cnki.net/</td></tr></tbody></table> <h3 id="知网期刊批量下载"><a href="#知网期刊批量下载" class="header-anchor">#</a> 知网期刊批量下载</h3> <p>以<a href="https://navi.cnki.net/knavi/journals/RJXB/detail?uniplatform=NZKPT" target="_blank" rel="noopener noreferrer">《软件学报》<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>为例，在chrome浏览器中打开地址，用户名密码登录后，按<code>F12</code>打开控制台，然后在控制台中输入下列代码：</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// 获取所有文章链接</span>
<span class="token keyword">const</span> aList <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'#CataLogContent .name a'</span><span class="token punctuation">)</span>
<span class="token comment">// 以每1秒的速度打开所有文章</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> aList<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> a <span class="token operator">=</span> aList<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
    <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">=&gt;</span>a<span class="token punctuation">.</span><span class="token function">click</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> i<span class="token operator">*</span><span class="token number">1000</span><span class="token punctuation">)</span>
<span class="token punctuation">}</span>
</code></pre></div><p>等文章全部打开后，用鼠标点击第一个自动打开的文章，然后点击<code>pdf下载</code>按钮，随后使用快捷键<code>ctrl</code>+<code>W</code>关闭当前标签，然后继续下一个页面的点击<code>pdf下载</code>按钮即可。</p> <h3 id="得到知识搜索"><a href="#得到知识搜索" class="header-anchor">#</a> 得到知识搜索</h3> <p><a href="https://www.dedao.cn/" target="_blank" rel="noopener noreferrer">得到搜索<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>可以搜索电子书的全文，并且可以任意试读10%章节。</p> <p>为了增加得到搜索的能力，可以在油猴脚本中增加下面代码：</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// ==UserScript==</span>
<span class="token comment">// @name         得到搜索</span>
<span class="token comment">// @namespace    http://tampermonkey.net/</span>
<span class="token comment">// @version      0.1</span>
<span class="token comment">// @description  try to take over the world!</span>
<span class="token comment">// @author       You</span>
<span class="token comment">// @match        https://www.dedao.cn/*</span>
<span class="token comment">// @run-at       document-end</span>
<span class="token comment">// @grant        unsafeWindow</span>
<span class="token comment">// @grant        GM_setClipboard</span>
<span class="token comment">// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js</span>
<span class="token comment">// ==/UserScript==</span>

<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token string">'use strict'</span><span class="token punctuation">;</span>

    <span class="token comment">// 创建按钮</span>
    <span class="token keyword">function</span> <span class="token function">create_button</span><span class="token punctuation">(</span>text<span class="token punctuation">,</span> id<span class="token punctuation">,</span> background<span class="token operator">=</span><span class="token string">&quot;#e33e33&quot;</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">const</span> button <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">&quot;button&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//创建一个按钮</span>
        button<span class="token punctuation">.</span>textContent <span class="token operator">=</span> text<span class="token punctuation">;</span> <span class="token comment">//按钮内容</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">$</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">#</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>id<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token function">$</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">#</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>id<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 如果已经有这个id的元素了，那么将其移除</span>
        button<span class="token punctuation">.</span>id <span class="token operator">=</span> id<span class="token punctuation">;</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>width <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>text<span class="token punctuation">.</span>length <span class="token operator">*</span> <span class="token number">20</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">px</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span> <span class="token comment">//根据按钮内容自动改变按钮宽度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token string">&quot;28px&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮高度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>align <span class="token operator">=</span> <span class="token string">&quot;center&quot;</span><span class="token punctuation">;</span> <span class="token comment">//文本居中</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>color <span class="token operator">=</span> <span class="token string">&quot;white&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮文字颜色</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>background <span class="token operator">=</span> background<span class="token punctuation">;</span> <span class="token comment">//按钮底色</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>border <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">1px solid </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>background<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span> <span class="token comment">//边框属性</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>borderRadius <span class="token operator">=</span> <span class="token string">&quot;4px&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮四个角弧度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>marginLeft <span class="token operator">=</span> <span class="token string">&quot;20px&quot;</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> button
    <span class="token punctuation">}</span>

    <span class="token comment">// 给指定id的元素增加复制事件</span>
    <span class="token keyword">function</span> <span class="token function">add_copy_event</span><span class="token punctuation">(</span><span class="token parameter">element_id<span class="token punctuation">,</span> copy_str</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token function">$</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">#</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>element_id<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">&quot;click&quot;</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止默认行为</span>
            e<span class="token punctuation">.</span><span class="token function">stopPropagation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止冒泡, 防止触发a标签事件</span>
            <span class="token function">GM_setClipboard</span><span class="token punctuation">(</span>copy_str<span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// 获得书籍信息</span>
    <span class="token keyword">function</span> <span class="token function">get_book_info</span><span class="token punctuation">(</span><span class="token parameter">book</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>book<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token string">&quot;&quot;</span>
        <span class="token keyword">const</span> book_name <span class="token operator">=</span> book<span class="token punctuation">.</span>operating_title
        <span class="token keyword">const</span> book_author <span class="token operator">=</span> book<span class="token punctuation">.</span>book_author
        <span class="token keyword">const</span> publish_time <span class="token operator">=</span> book<span class="token punctuation">.</span>publish_time
        <span class="token keyword">return</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>book_author<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">. </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>book_name<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">[M]. 出版社, </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>publish_time<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">.</span><span class="token template-punctuation string">`</span></span>
    <span class="token punctuation">}</span>

    <span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">// 拦截页面的所有XMLHttpRequest请求</span>
        <span class="token keyword">var</span> origOpen <span class="token operator">=</span> <span class="token class-name">XMLHttpRequest</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span>open<span class="token punctuation">;</span>
        <span class="token class-name">XMLHttpRequest</span><span class="token punctuation">.</span>prototype<span class="token punctuation">.</span><span class="token function-variable function">open</span> <span class="token operator">=</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">this</span><span class="token punctuation">.</span><span class="token function">addEventListener</span><span class="token punctuation">(</span><span class="token string">'load'</span><span class="token punctuation">,</span> <span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>readyState <span class="token operator">===</span> <span class="token number">4</span> <span class="token operator">&amp;&amp;</span> <span class="token keyword">this</span><span class="token punctuation">.</span>responseURL<span class="token punctuation">.</span><span class="token function">endsWith</span><span class="token punctuation">(</span><span class="token string">&quot;searchebookcontent&quot;</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                    console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token string">&quot;开始处理&quot;</span><span class="token punctuation">)</span>
                    <span class="token keyword">const</span> content <span class="token operator">=</span> <span class="token constant">JSON</span><span class="token punctuation">.</span><span class="token function">parse</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>responseText<span class="token punctuation">)</span>
                    <span class="token keyword">const</span> page <span class="token operator">=</span> content<span class="token punctuation">.</span>c <span class="token operator">?</span> content<span class="token punctuation">.</span>c<span class="token punctuation">.</span>page <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token comment">// 获取页码</span>
                    <span class="token keyword">const</span> size <span class="token operator">=</span> content<span class="token punctuation">.</span>c <span class="token operator">?</span> content<span class="token punctuation">.</span>c<span class="token punctuation">.</span>size <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">;</span> <span class="token comment">// 获取每页大小</span>
                    <span class="token keyword">let</span> previous_num <span class="token operator">=</span> <span class="token punctuation">(</span>page <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">*</span> size
                    <span class="token comment">// 获取书籍信息</span>
                    <span class="token keyword">const</span> book <span class="token operator">=</span> content<span class="token punctuation">.</span>c <span class="token operator">?</span> content<span class="token punctuation">.</span>c<span class="token punctuation">.</span>book <span class="token operator">:</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
                    <span class="token keyword">let</span> book_str <span class="token operator">=</span> <span class="token function">get_book_info</span><span class="token punctuation">(</span>book<span class="token punctuation">)</span>

                    <span class="token comment">// 章节列表</span>
                    <span class="token keyword">const</span> chapter_list <span class="token operator">=</span> content<span class="token punctuation">.</span>c <span class="token operator">?</span> content<span class="token punctuation">.</span>c<span class="token punctuation">.</span>list <span class="token operator">:</span> <span class="token keyword">null</span>
                    <span class="token keyword">let</span> all_chapter_str <span class="token operator">=</span> <span class="token string">&quot;&quot;</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span>chapter_list<span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> chapter_list<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                            <span class="token keyword">let</span> chapter <span class="token operator">=</span> chapter_list<span class="token punctuation">[</span>i<span class="token punctuation">]</span>
                            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span>chapter<span class="token punctuation">.</span>Chapter<span class="token punctuation">)</span><span class="token keyword">continue</span><span class="token punctuation">;</span>
                            <span class="token comment">// 增加所有段落信息</span>
                            all_chapter_str <span class="token operator">+=</span> chapter<span class="token punctuation">.</span>Chapter <span class="token operator">+</span> <span class="token string">&quot;========================================\n\n&quot;</span>
                            <span class="token comment">// 增加单段落信息</span>
                            <span class="token keyword">const</span> chapter_btn <span class="token operator">=</span> <span class="token function">create_button</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">复制段落</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>previous_num<span class="token operator">+</span>i<span class="token operator">+</span><span class="token number">1</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">chapter-</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>previous_num<span class="token operator">+</span>i<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">-btn</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span><span class="token string">'#5c7cfa'</span><span class="token punctuation">)</span>
                            <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;li.list-item&quot;</span><span class="token punctuation">)</span><span class="token punctuation">[</span>previous_num<span class="token operator">+</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">appendChild</span><span class="token punctuation">(</span>chapter_btn<span class="token punctuation">)</span><span class="token punctuation">;</span>
                            <span class="token function">add_copy_event</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">chapter-</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>previous_num<span class="token operator">+</span>i<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">-btn</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">,</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">\n---------</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>book_str<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> 开始---------\n\n</span><span class="token template-punctuation string">`</span></span><span class="token operator">+</span>chapter<span class="token punctuation">.</span>Chapter<span class="token operator">+</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">\n---------</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>book_str<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"> 结束---------\n</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                        <span class="token punctuation">}</span>
                    <span class="token punctuation">}</span>
                    <span class="token keyword">const</span> book_info_btn <span class="token operator">=</span> <span class="token function">create_button</span><span class="token punctuation">(</span><span class="token string">&quot;复制书籍信息&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;bookInfo_cp_btn&quot;</span><span class="token punctuation">)</span>
                    <span class="token keyword">const</span> chapter_content_btn <span class="token operator">=</span> <span class="token function">create_button</span><span class="token punctuation">(</span><span class="token string">&quot;复制所有段落&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;allChapter_cp_btn&quot;</span><span class="token punctuation">)</span>
                    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.ebook-detail'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>parentNode<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>book_info_btn<span class="token punctuation">)</span>
                    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">'.ebook-detail'</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span>parentNode<span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>chapter_content_btn<span class="token punctuation">)</span>
                    <span class="token function">add_copy_event</span><span class="token punctuation">(</span><span class="token string">&quot;bookInfo_cp_btn&quot;</span><span class="token punctuation">,</span> book_str<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token function">add_copy_event</span><span class="token punctuation">(</span><span class="token string">&quot;allChapter_cp_btn&quot;</span><span class="token punctuation">,</span> all_chapter_str<span class="token punctuation">)</span><span class="token punctuation">;</span>

                    <span class="token comment">// 增加段落高度，保证内容都能显示</span>
                    <span class="token keyword">const</span> para_list <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;.list-item .summary.iget-common-f4.iget-common-c1&quot;</span><span class="token punctuation">)</span>
                    <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> para_list<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                        <span class="token keyword">const</span> content_length <span class="token operator">=</span> para_list<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>innerHTML<span class="token punctuation">.</span>length
                        para_list<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">.</span>style<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>content_length <span class="token operator">*</span> <span class="token number">0.7</span> <span class="token operator">&lt;</span> <span class="token number">50</span> <span class="token operator">?</span> <span class="token number">50</span> <span class="token operator">:</span> content_length <span class="token operator">*</span> <span class="token number">0.7</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">px</span><span class="token template-punctuation string">`</span></span>
                    <span class="token punctuation">}</span>
                <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token function">origOpen</span><span class="token punctuation">.</span><span class="token function">apply</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">,</span> arguments<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p><img src="https://pic.imgdb.cn/item/6106d3985132923bf8128c39.jpg" alt="原版得到搜索"></p> <p>原版得到搜索如上图所示，使用得到搜索增强的脚本时，在电子书信息搜索增加了两个功能，<strong>一是</strong>能够一键复制段落内容和书籍信息，并且内容比网址显示的更多更全面，二是扩大了网页的段落显示，效果如下所示。</p> <p><img src="https://pic.imgdb.cn/item/6106d41a5132923bf814c5b0.jpg" alt="得到搜索（脚本增强版）"></p> <h2 id="全文翻译英文技术文档和书籍"><a href="#全文翻译英文技术文档和书籍" class="header-anchor">#</a> 全文翻译英文技术文档和书籍</h2> <h3 id="mobi、epub等格式的英文技术文档全文翻译"><a href="#mobi、epub等格式的英文技术文档全文翻译" class="header-anchor">#</a> mobi、epub等格式的英文技术文档全文翻译</h3> <p><strong>第一步</strong>，下载最新的英文技术书籍，可以到<a href="https://salttiger.com/" target="_blank" rel="noopener noreferrer">SaltTiger<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>下载，也可以通过在<a href="http://libgen.is/search.php" target="_blank" rel="noopener noreferrer">libgen<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>进行关键词搜索。</p> <p><strong>第二步</strong>，将电子书导入到<a href="https://calibre-ebook.com/download_windows" target="_blank" rel="noopener noreferrer">Calibre<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>电子书管理软件中，然后把epub或者mobi格式电子书转换为calibre自带的<code>htmlz</code>格式，如下图右上角所示。</p> <p><img src="https://pic.imgdb.cn/item/60f830315132923bf8376274.jpg" alt="转换为htmlz格式"></p> <p><strong>第三步</strong>，将<code>htmlz</code>格式的电子书扩展名改为<code>zip</code>，然后解压，解压后的文件目录如下所示。</p> <p><img src="https://pic.imgdb.cn/item/60f8309f5132923bf83a6dff.jpg" alt="htmlz解压"></p> <p><strong>第四步</strong>，使用chrome浏览器打开<code>index.html</code>文件，能够正常阅读，然后打开chrome自带的<code>翻译</code>功能，此时会将当页内容翻译为中文，对于<code>&lt;code&gt;</code>标签包裹的内容，chrome浏览器会保持原样输出，翻译前如下图所示：</p> <p><img src="https://pic.imgdb.cn/item/60f8318f5132923bf84129d1.jpg" alt="原文样式"></p> <p>使用chrome浏览器翻译后的效果如下：</p> <p><img src="https://pic.imgdb.cn/item/60f831f35132923bf843d03f.jpg" alt="翻译后的样式"></p> <p>但是采用这种翻译只对当前页面有效，需要进一步优化。</p> <p><strong>第五步</strong>，使用js代码让页面自动滚动，按“F12”键，打开控制台标签“console”，然后在控制台输入下面代码：</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">let</span> pagePos <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
<span class="token function">setInterval</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    pagePos <span class="token operator">+=</span> <span class="token number">100</span><span class="token punctuation">;</span>
    <span class="token function">scroll</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span>pagePos<span class="token punctuation">)</span>
<span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token number">500</span><span class="token punctuation">)</span>
</code></pre></div><p>上述代码表示每500毫秒往下滚动100像素高度，这样页面就自动开始滚动，结合chrome浏览器的自动翻译，就可以自动翻译整个页面全文。</p> <p>最后使用快捷键<code>ctrl</code>+<code>s</code>保存页面。</p> <p><strong>第六步</strong>，保存页面之后，对于书签等<code>&lt;a&gt;</code>标签跳转链接，可能使用的源文件路径，此时需要形如<code>file://xxx</code>的开头部分删除掉，只留下hash路径，即形如<code>#calibre</code>部分，这样就能自动跳转。通常可以使用vscode的替换功能全文搜索替换。</p> <h3 id="pdf格式的英文文档全文翻译"><a href="#pdf格式的英文文档全文翻译" class="header-anchor">#</a> pdf格式的英文文档全文翻译</h3> <p>在<a href="https://www.rand.org/pubs/research_reports.html" target="_blank" rel="noopener noreferrer">兰德<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>官网下载英文报告一般为pdf格式，怎么样较好的进行全文翻译呢？</p> <p>首先，将下载的pdf文档转换成为html文件，使用<code>pdfelement</code>即可，点击<code>转换</code>标签页，选择<code>转换为html</code>按钮，如下图所示。</p> <p><img src="https://pic.imgdb.cn/item/60f83feb5132923bf8a68223.jpg" alt="转换为html"></p> <p>然后对转换后的html文件进行处理，去除掉不必要的换行符，一般在vscode中进行操作，主要有如下操作</p> <ul><li>将<code>-&lt;/br&gt;</code>删除</li> <li>将<code>&lt;/br&gt;</code>替换为空格</li> <li>将所有的两个空格替换为一个空格</li></ul> <p>然后就可以按照之前的方法，使用chrome进行翻译了。</p> <div class="custom-block tip"><p class="custom-block-title">提示</p> <p>可以使用<a href="https://fanyi.caiyunapp.com/#/web" target="_blank" rel="noopener noreferrer">彩云小译<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>的chrome插件，实现中英文对照翻译效果</p></div> <h3 id="英文pdf使用有道文档翻译-网易翻译"><a href="#英文pdf使用有道文档翻译-网易翻译" class="header-anchor">#</a> 英文pdf使用有道文档翻译(网易翻译)</h3> <p>进入<a href="https://pdf.youdao.com/" target="_blank" rel="noopener noreferrer">有道文档翻译<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>，登录后上传pdf文件（不得大于10MB）。</p> <p>为了能够自动滚动页面和批量下载图片，需要在油猴脚本（Tampermonkey）中加载脚本，脚本全文如下：</p> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// ==UserScript==</span>
<span class="token comment">// @name         有道文档翻译图片下载</span>
<span class="token comment">// @namespace    http://tampermonkey.net/</span>
<span class="token comment">// @version      0.1</span>
<span class="token comment">// @description  try to take over the world!</span>
<span class="token comment">// @author       You</span>
<span class="token comment">// @match        https://pdf.youdao.com/docview.html*</span>
<span class="token comment">// @grant        GM_openInTab</span>
<span class="token comment">// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js</span>
<span class="token comment">// ==/UserScript==</span>

<span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token string">'use strict'</span><span class="token punctuation">;</span>

    <span class="token comment">// 创建按钮</span>
    <span class="token keyword">function</span> <span class="token function">create_button</span><span class="token punctuation">(</span>text<span class="token punctuation">,</span> id<span class="token punctuation">,</span> background<span class="token operator">=</span><span class="token string">&quot;#e33e33&quot;</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">const</span> button <span class="token operator">=</span> document<span class="token punctuation">.</span><span class="token function">createElement</span><span class="token punctuation">(</span><span class="token string">&quot;button&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">//创建一个按钮</span>
        button<span class="token punctuation">.</span>textContent <span class="token operator">=</span> text<span class="token punctuation">;</span> <span class="token comment">//按钮内容</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">$</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">#</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>id<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span> <span class="token punctuation">)</span><span class="token function">$</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">#</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>id<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">remove</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 如果已经有这个id的元素了，那么将其移除</span>
        button<span class="token punctuation">.</span>id <span class="token operator">=</span> id<span class="token punctuation">;</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>width <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>text<span class="token punctuation">.</span>length <span class="token operator">*</span> <span class="token number">20</span><span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">px</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span> <span class="token comment">//根据按钮内容自动改变按钮宽度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>height <span class="token operator">=</span> <span class="token string">&quot;28px&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮高度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>align <span class="token operator">=</span> <span class="token string">&quot;center&quot;</span><span class="token punctuation">;</span> <span class="token comment">//文本居中</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>color <span class="token operator">=</span> <span class="token string">&quot;white&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮文字颜色</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>background <span class="token operator">=</span> background<span class="token punctuation">;</span> <span class="token comment">//按钮底色</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>border <span class="token operator">=</span> <span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">1px solid </span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>background<span class="token interpolation-punctuation punctuation">}</span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span> <span class="token comment">//边框属性</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>borderRadius <span class="token operator">=</span> <span class="token string">&quot;4px&quot;</span><span class="token punctuation">;</span> <span class="token comment">//按钮四个角弧度</span>
        button<span class="token punctuation">.</span>style<span class="token punctuation">.</span>marginLeft <span class="token operator">=</span> <span class="token string">&quot;20px&quot;</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> button
    <span class="token punctuation">}</span>

    <span class="token comment">// 下载图片的功能</span>
    <span class="token keyword">function</span> <span class="token function">download_imgs</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">const</span> trans_elements <span class="token operator">=</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#docTranslationImg .doc-img-wrapper img&quot;</span><span class="token punctuation">)</span>
        console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string">共需要下载</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>trans_elements<span class="token punctuation">.</span>length<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string">张图片</span><span class="token template-punctuation string">`</span></span><span class="token punctuation">)</span>
        <span class="token keyword">for</span><span class="token punctuation">(</span><span class="token keyword">let</span> i <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span> i <span class="token operator">&lt;</span> trans_elements<span class="token punctuation">.</span>length<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token keyword">const</span> img_ele <span class="token operator">=</span> trans_elements<span class="token punctuation">[</span>i<span class="token punctuation">]</span><span class="token punctuation">;</span>
            <span class="token keyword">let</span> img_url <span class="token operator">=</span> img_ele<span class="token punctuation">.</span>dataset<span class="token operator">?</span>img_ele<span class="token punctuation">.</span>dataset<span class="token punctuation">.</span>src<span class="token operator">:</span>img_ele<span class="token punctuation">.</span>src <span class="token comment">// 获得url</span>
            <span class="token comment">// 间隔0.8秒下载下一张图片</span>
            <span class="token function">setTimeout</span><span class="token punctuation">(</span><span class="token keyword">function</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">GM_openInTab</span><span class="token punctuation">(</span>img_url<span class="token punctuation">)</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span> i<span class="token operator">*</span><span class="token number">800</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>
    <span class="token punctuation">}</span>
    <span class="token comment">// 是否滚动到页面底部</span>
    <span class="token keyword">function</span> <span class="token function">is_scroll_bottom</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// const $ele = $(`#${element_id}`)</span>
        <span class="token comment">// const sum_height = $ele.prop('scrollHeight') // 总高度</span>
        <span class="token comment">// const current_height = $ele.scrollTop() // 当前滚动高度</span>
        <span class="token comment">// // 如果差距小于500，说明已经到页面底部了</span>
        <span class="token comment">// if(sum_height-current_height &lt; 500 ) return true</span>
        <span class="token comment">// return false</span>
        <span class="token comment">// 改为通过判断是否出现正在翻译的提示来判断</span>
        <span class="token keyword">return</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#loaderProgress&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token string">&quot;display&quot;</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token string">'block'</span>
    <span class="token punctuation">}</span>

    <span class="token comment">// 判断是否到达文档末尾</span>
    <span class="token keyword">function</span> <span class="token function">is_end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#payContainer&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">css</span><span class="token punctuation">(</span><span class="token string">&quot;display&quot;</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token string">'block'</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">var</span> is_auto_scroll <span class="token operator">=</span> <span class="token boolean">false</span>
    <span class="token keyword">var</span> pagePos <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">;</span>
    <span class="token comment">// 自动滚动功能</span>
    <span class="token keyword">function</span> <span class="token function">auto_scroll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token comment">// 自动滚动，使用setTimeout递归调用</span>
        <span class="token keyword">function</span> <span class="token function">_auto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
            <span class="token comment">// 到达文档末尾则停止滚动并自动下载图片</span>
            console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span><span class="token function">is_end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token function">is_end</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                is_auto_scroll <span class="token operator">=</span> <span class="token boolean">false</span>
                <span class="token function">download_imgs</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
            <span class="token comment">// 如果没有到达底部，则位置继续向下</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token operator">!</span><span class="token function">is_scroll_bottom</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span>pagePos <span class="token operator">+=</span> <span class="token number">370</span><span class="token punctuation">;</span>
            document<span class="token punctuation">.</span><span class="token function">getElementById</span><span class="token punctuation">(</span><span class="token string">&quot;docTranslationImg&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">scroll</span><span class="token punctuation">(</span><span class="token number">0</span><span class="token punctuation">,</span>pagePos<span class="token punctuation">)</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>is_auto_scroll<span class="token punctuation">)</span><span class="token punctuation">{</span>
                <span class="token function">setTimeout</span><span class="token punctuation">(</span>_auto<span class="token punctuation">,</span> <span class="token number">250</span><span class="token punctuation">)</span>
            <span class="token punctuation">}</span>
        <span class="token punctuation">}</span>
        <span class="token function">_auto</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 调用函数</span>
    <span class="token punctuation">}</span>

    <span class="token keyword">function</span> <span class="token function">start_or_pause_scroll</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>is_auto_scroll<span class="token punctuation">)</span><span class="token punctuation">{</span>
            is_auto_scroll<span class="token operator">=</span><span class="token boolean">false</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token keyword">else</span><span class="token punctuation">{</span>
            is_auto_scroll <span class="token operator">=</span> <span class="token boolean">true</span>
            <span class="token function">auto_scroll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span>

    <span class="token punctuation">}</span>

    <span class="token comment">// 创建下载译文图片按钮</span>
    <span class="token keyword">const</span> download_all_btn <span class="token operator">=</span> <span class="token function">create_button</span><span class="token punctuation">(</span><span class="token string">&quot;下载图片&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;download_all_btn&quot;</span><span class="token punctuation">)</span>
    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#docTranslation div&quot;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>download_all_btn<span class="token punctuation">)</span>
    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#download_all_btn&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">&quot;click&quot;</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止默认行为</span>
        e<span class="token punctuation">.</span><span class="token function">stopPropagation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止冒泡, 防止触发a标签事件</span>
        <span class="token function">download_imgs</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

    <span class="token keyword">const</span> auto_scroll_btn <span class="token operator">=</span> <span class="token function">create_button</span><span class="token punctuation">(</span><span class="token string">&quot;开始/暂停滚动&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;auto_scroll_btn&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;#74b816&quot;</span><span class="token punctuation">)</span>
    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#docTranslation div&quot;</span><span class="token punctuation">)</span><span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">append</span><span class="token punctuation">(</span>auto_scroll_btn<span class="token punctuation">)</span>
    <span class="token function">$</span><span class="token punctuation">(</span><span class="token string">&quot;#auto_scroll_btn&quot;</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">on</span><span class="token punctuation">(</span><span class="token string">&quot;click&quot;</span><span class="token punctuation">,</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">e</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        e<span class="token punctuation">.</span><span class="token function">preventDefault</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止默认行为</span>
        e<span class="token punctuation">.</span><span class="token function">stopPropagation</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// 阻止冒泡, 防止触发a标签事件</span>
        <span class="token function">start_or_pause_scroll</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><p>将上面的代码复制到油猴脚本中保存即可，以后再批量下载图片就可以直接使用了。</p> <p>加载完成后，刷新有道文档翻译界面，会在译文区增加两个按钮功能，如下图所示：</p> <p><img src="https://pic.imgdb.cn/item/6106cf855132923bf8fff871.jpg" alt="译文区按钮"></p> <p>其中<code>开始/暂停滚动</code>是让页面自动滚动，每次滚动到末尾时，有道会加载新页面，所以需要不停下滚，<strong>为了能触发自动加载新页面，需要把鼠标放到译文区</strong>，<code>下载图片</code>则是以<code>tran-页码.jpg</code>的形式，将所有已经下载或的页面全部下载下来。</p> <p>为了方便操作，点击<code>开始/暂停滚动</code>之后，<strong>如果滚动到文档末尾，会自动触发下载图片功能</strong>，方便获取全文。</p> <p>使用该方法得到的图片如下所示，可以再使用“acrobat”或者“pdfelement”将其合并成一个pdf，然后使用“abbyy”进行文字识别。</p> <p><img src="https://pic.imgdb.cn/item/6106d0ec5132923bf8065893.jpg" alt="使用有道文档下载的译文图片集合"></p> <h3 id="删除有道文档翻译下载的所有翻译图片并生成pdf合集"><a href="#删除有道文档翻译下载的所有翻译图片并生成pdf合集" class="header-anchor">#</a> 删除有道文档翻译下载的所有翻译图片并生成pdf合集</h3> <p>使用python的<code>img2pdf</code>模块，首先<code>pip install img2pdf</code>安装模块，然后新建python文件后输入下面代码：</p> <div class="language-python extra-class"><pre class="language-python"><code><span class="token keyword">import</span> os
<span class="token keyword">import</span> time
<span class="token keyword">from</span> PIL <span class="token keyword">import</span> Image
<span class="token keyword">import</span> img2pdf

<span class="token comment"># 图片文件目录</span>
DOWNLOAD_PATH <span class="token operator">=</span> <span class="token string">r&quot;E:\Downloads&quot;</span>
<span class="token comment"># 合并成功后是否删除文件</span>
IS_DELETE_FILE <span class="token operator">=</span> <span class="token boolean">True</span>
<span class="token comment"># 是否压缩文件</span>
IS_COMPRESS <span class="token operator">=</span> <span class="token boolean">True</span>
<span class="token comment"># 压缩图片质量，默认为80</span>
IMG_QUALITY <span class="token operator">=</span> <span class="token number">80</span>


<span class="token keyword">def</span> <span class="token function">compress_img</span><span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token triple-quoted-string string">&quot;&quot;&quot;
    压缩jpg文件
    :param jpg_list: 图片文件位置列表
    :return:
    &quot;&quot;&quot;</span>
    <span class="token keyword">for</span> jpg_path <span class="token keyword">in</span> jpg_list<span class="token punctuation">:</span>
        <span class="token comment"># 使用pillow库打开文件并压缩</span>
        <span class="token keyword">with</span> Image<span class="token punctuation">.</span><span class="token builtin">open</span><span class="token punctuation">(</span>jpg_path<span class="token punctuation">)</span> <span class="token keyword">as</span> im<span class="token punctuation">:</span>
            im<span class="token punctuation">.</span>save<span class="token punctuation">(</span>jpg_path <span class="token operator">+</span> <span class="token string">&quot;.jpg&quot;</span><span class="token punctuation">,</span> quality<span class="token operator">=</span>IMG_QUALITY<span class="token punctuation">)</span>
        os<span class="token punctuation">.</span>remove<span class="token punctuation">(</span>jpg_path<span class="token punctuation">)</span>  <span class="token comment"># 删除压缩前的原文件</span>
        <span class="token comment"># 将压缩后的文件保存为压缩前的名字</span>
        os<span class="token punctuation">.</span>rename<span class="token punctuation">(</span>jpg_path <span class="token operator">+</span> <span class="token string">&quot;.jpg&quot;</span><span class="token punctuation">,</span> jpg_path<span class="token punctuation">)</span>


<span class="token keyword">def</span> <span class="token function">from_photo_to_pdf</span><span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span><span class="token punctuation">:</span>
    <span class="token triple-quoted-string string">&quot;&quot;&quot;
    将图片文件地址的列表合并成一个pdf文件
    :param jpg_list: 图片文件位置列表，例如[&quot;E:\Downloads\tran-0.jpeg','E:\Downloads\tran-1.jpeg]
    :return:合并的pdf文件位置
    &quot;&quot;&quot;</span>

    <span class="token comment"># 按照A4大小自定义pdf文件的单页的宽和高</span>
    a4 <span class="token operator">=</span> <span class="token punctuation">(</span>img2pdf<span class="token punctuation">.</span>mm_to_pt<span class="token punctuation">(</span><span class="token number">720</span><span class="token punctuation">)</span><span class="token punctuation">,</span> img2pdf<span class="token punctuation">.</span>mm_to_pt<span class="token punctuation">(</span><span class="token number">1080</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    layout_fun <span class="token operator">=</span> img2pdf<span class="token punctuation">.</span>get_layout_fun<span class="token punctuation">(</span>a4<span class="token punctuation">)</span>
    time_now <span class="token operator">=</span> time<span class="token punctuation">.</span>strftime<span class="token punctuation">(</span><span class="token string">'%Y%m%d_%H%M%S'</span><span class="token punctuation">,</span>time<span class="token punctuation">.</span>localtime<span class="token punctuation">(</span>time<span class="token punctuation">.</span>time<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    pdf <span class="token operator">=</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>DOWNLOAD_PATH<span class="token punctuation">,</span> <span class="token string">&quot;转换_%s.pdf&quot;</span> <span class="token operator">%</span><span class="token punctuation">(</span>time_now<span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">with</span> <span class="token builtin">open</span><span class="token punctuation">(</span>pdf<span class="token punctuation">,</span> <span class="token string">'wb'</span><span class="token punctuation">)</span> <span class="token keyword">as</span> f<span class="token punctuation">:</span>
        f<span class="token punctuation">.</span>write<span class="token punctuation">(</span>img2pdf<span class="token punctuation">.</span>convert<span class="token punctuation">(</span>jpg_list<span class="token punctuation">,</span> layout_fun<span class="token operator">=</span>layout_fun<span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">return</span> pdf


jpg_list <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span>
page_i <span class="token operator">=</span> <span class="token number">0</span>
<span class="token comment"># 获取所有的翻译后的jpeg文件，由于翻译后的文件是按照tran-0.jpeg, tran-1.jpeg排序的，因此进行遍历</span>
<span class="token keyword">while</span> <span class="token boolean">True</span><span class="token punctuation">:</span>
    jpg_file <span class="token operator">=</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>DOWNLOAD_PATH<span class="token punctuation">,</span> <span class="token string">&quot;tran-%s.jpeg&quot;</span> <span class="token operator">%</span> <span class="token punctuation">(</span>page_i<span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> <span class="token keyword">not</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>jpg_file<span class="token punctuation">)</span><span class="token punctuation">:</span>
        <span class="token keyword">break</span>
    <span class="token comment"># 重复图片文件处理，有时候会出现多下载了一次文件的情况，此时文件夹会出现两张相同照片</span>
    <span class="token comment"># 例如“tran-91.jpeg”和“tran-91 (1).jpeg”，如果相同则删除重复文件</span>
    duplication_file <span class="token operator">=</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>join<span class="token punctuation">(</span>DOWNLOAD_PATH<span class="token punctuation">,</span> <span class="token string">&quot;tran-%s (1).jpeg&quot;</span> <span class="token operator">%</span> <span class="token punctuation">(</span>page_i<span class="token punctuation">,</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
    <span class="token keyword">if</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>duplication_file<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>getsize<span class="token punctuation">(</span>duplication_file<span class="token punctuation">)</span> <span class="token operator">==</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>getsize<span class="token punctuation">(</span>jpg_file<span class="token punctuation">)</span><span class="token punctuation">:</span>
        os<span class="token punctuation">.</span>remove<span class="token punctuation">(</span>duplication_file<span class="token punctuation">)</span>
    jpg_list<span class="token punctuation">.</span>append<span class="token punctuation">(</span>jpg_file<span class="token punctuation">)</span>
    page_i <span class="token operator">+=</span> <span class="token number">1</span>

<span class="token comment"># 合并pdf文件，当图片列表大于零才新生成pdf</span>
<span class="token keyword">if</span> <span class="token builtin">len</span><span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span> <span class="token operator">==</span> <span class="token number">0</span><span class="token punctuation">:</span>
    <span class="token keyword">raise</span> RuntimeError<span class="token punctuation">(</span><span class="token string">&quot;文件夹[%s]中没有指定图片&quot;</span> <span class="token operator">%</span> DOWNLOAD_PATH<span class="token punctuation">)</span>
<span class="token comment"># 压缩文件</span>
<span class="token keyword">if</span> IS_COMPRESS<span class="token punctuation">:</span>
    <span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&quot;正在压缩%s张图片&quot;</span> <span class="token operator">%</span> <span class="token builtin">len</span><span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span><span class="token punctuation">)</span>
    compress_img<span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span>
<span class="token comment"># 获得合并后的pdf</span>
merged_pdf <span class="token operator">=</span> from_photo_to_pdf<span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span>

<span class="token comment"># 如果允许删除源文件，同时生成的pdf存在且大于100KB，则删除源图片文件</span>
<span class="token keyword">if</span> IS_DELETE_FILE <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>exists<span class="token punctuation">(</span>merged_pdf<span class="token punctuation">)</span> <span class="token keyword">and</span> os<span class="token punctuation">.</span>path<span class="token punctuation">.</span>getsize<span class="token punctuation">(</span>merged_pdf<span class="token punctuation">)</span> <span class="token operator">&gt;</span> <span class="token number">100</span><span class="token operator">*</span><span class="token number">1024</span><span class="token punctuation">:</span>
    <span class="token keyword">for</span> jpg <span class="token keyword">in</span> jpg_list<span class="token punctuation">:</span>
        os<span class="token punctuation">.</span>remove<span class="token punctuation">(</span>jpg<span class="token punctuation">)</span>
<span class="token keyword">print</span><span class="token punctuation">(</span><span class="token string">&quot;一共合并%s张图片，pdf文件位于%s，运行结束&quot;</span> <span class="token operator">%</span> <span class="token punctuation">(</span><span class="token builtin">len</span><span class="token punctuation">(</span>jpg_list<span class="token punctuation">)</span><span class="token punctuation">,</span>merged_pdf<span class="token punctuation">)</span><span class="token punctuation">)</span>
</code></pre></div><p>其中，<code>DOWNLOAD_PATH</code>是下载的图片文件目录，需要根据情况进行指定，我本机位置是<code>E:\Downloads</code>，最后的输出结果像这样：<code>一共合并98张图片，pdf文件位于E:\Downloads\转换_20210829_003206.pdf，运行结束</code>。</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">更新于:</span> <span class="time">7/3/2022, 7:31:05 PM</span></div></footer> <div class="page-nav"><p class="inner"><!----> <span class="next"><a href="/paper/search.html">
        无人机搜索
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.9e067b79.js" defer></script><script src="/assets/js/2.983eb755.js" defer></script><script src="/assets/js/59.5ab55a80.js" defer></script>
  </body>
</html>
